package com.gdk.ksoft.assembly.exception;

import android.content.Context;

import com.gdk.ksoft.data.common.SystemData;
import com.gdk.ksoft.data.entry.tables.ExceptionTable;
import com.gdk.ksoft.assembly.utils.extensions.FormatUtils;
import com.gdk.ksoft.assembly.utils.system.SQLiteUtils;

import java.util.Date;

/**
 * Created by hel on 2014-12-19.
 * 异常扩展类
 */
public class ExceptionEx  extends Exception{

    private Context context;
    private int errType = 0;

    /**
     * 构造函数
     * @param context
     */
    public ExceptionEx(Context context,int errType){
        super();
        this.context = context;
        this.errType = errType;
    }

    public ExceptionEx(Context context,String message,int errType){
        super(message);
        this.context = context;
        this.errType = errType;
    }

    @Override
    public void printStackTrace() {
        try{
            ExceptionTable exceptionTable = new ExceptionTable();
            exceptionTable.err_imei = SystemData.PhoneIMEI;
            exceptionTable.err_type = errType;
            exceptionTable.err_msg = this.getLocalizedMessage()+"\r\n"+this.getMessage();
            exceptionTable.err_time = FormatUtils.standardDatetime(new Date(), "yyyy-MM-dd HH:mm:ss");
            SQLiteUtils.getInstance(context).getDbUtils().save(exceptionTable);//记录异常到数据库
        }catch (Exception e){
            e.printStackTrace();
        }
        super.printStackTrace();
    }
}
